import { Column, Entity, ManyToOne } from 'typeorm'
import { SessionAnalytics } from './session-analytics.model'
import { EventTypes } from '@boticord/analytics/event-types.enum'
import { DiscordID } from '@boticord/common'

@Entity()
export class EventAnalytics extends DiscordID {
  @Column({ enum: EventTypes })
  declare type: EventTypes

  @Column({ nullable: true })
  declare userID?: string // encrypted user affected

  @Column({ nullable: true })
  declare affectedID?: string // non-null when something with affected is affected

  @Column()
  declare userAgent: string // requests without user agent will be rejected.

  @ManyToOne(() => SessionAnalytics, s => s.events)
  declare session: SessionAnalytics

  @Column({ type: 'bigint' }) // bigint required by postgres
  declare timestamp: number
}